package de.mafr.jsystest.matchers;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;

/**
 * Syntactic sugar, decorates another matcher.
 * 
 * This is very similar to hamcrest's Is matcher.
 */
public class Has<T> extends BaseMatcher<T> {
	private final Matcher<T> matcher;
	
	public Has(Matcher<T> matcher) {
		this.matcher = matcher;
	}
	
	public boolean matches(Object actual) {
		return matcher.matches(actual);
	}

	public void describeTo(Description description) {
		description.appendText("has ").appendDescriptionOf(matcher);
	}
	
    @Factory
    public static <T> Matcher<T> has(Matcher<T> matcher) {
        return new Has<T>(matcher);
    }
}
